package com.turing.sensivitycode.controller;

import com.turing.common.response.ResponseVO;
import com.turing.common.util.ResponseUtil;
import com.turing.sensivitycode.domain.SensivityCode;
import com.turing.sensivitycode.service.SensivityCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 操作敏感词
 */
@RestController
@RequestMapping(value = "/sensivity")
public class SensivityCodeController {


    @Autowired
    private SensivityCodeService sensivityCodeService;

    /**
     *
     * 在敏感词库中新增敏感词
     *
     * @param sensivityCode 词库名称
     * @param lecId       词库库ID
     * @return
     */
    @PostMapping(value = "/createSensivityCode")
    public ResponseVO<String> createSensivityCode(@RequestParam(value = "sensivityCode") String sensivityCode, @RequestParam(value = "lecId") Integer lecId) {
        return ResponseUtil.success(sensivityCodeService.insertSensivityCode(sensivityCode, lecId));
    }

    /**
     * 根据敏感词库ID会来查询所有的敏感词在页面上来进行显示
     * @param lecId
     * @return
     */
    @PostMapping(value = "/queryAllSensivityCodeByLecid")
    public ResponseVO<List<SensivityCode>> queryAllSensivityCodeByLecid(@RequestParam(value = "lecId") Integer lecId) {
        return ResponseUtil.success(sensivityCodeService.queryAllSensivityCodeByLecid( lecId));
    }


    /**
     * 根据词库ID和敏感词ID来对其进行删除
     * @param sensivityCodeID 敏感词对应的ID
     * @param lecId
     * @return
     */
    @PostMapping(value = "/deleteSensivityCodeByLecIdAndSensivityCodeID")
    public ResponseVO<String> deleteSensivityCodeByLecIdAndSensivityCodeID(@RequestParam(value = "sensivityCodeID") Integer sensivityCodeID, @RequestParam(value = "lecId") Integer lecId) {
        return ResponseUtil.success(sensivityCodeService.deleteSensivityCodeByLecIdAndSensivityCodeID(sensivityCodeID, lecId));
    }




    @PostMapping(value = "/createSensivityCodeByExcel")
    public ResponseVO<String> createSensivityLexcionByExcel(@RequestParam(value = "lecId") Integer lecId, @RequestPart MultipartFile[] multipartFiles) {
        return ResponseUtil.success(sensivityCodeService.createSensivityCodeByExcel( lecId,multipartFiles));
    }

}
